package com.tuanbiao.models.action;

import com.hzjq.data.entity.CapDelayEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.cap.bean.ReadResult;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import timber.log.Timber;

/**
 * @author abiao
 * @since 2022/4/20 14:40
 */
public interface DelayAction {
    default void getDelay(OnBaseResultCallback<CapDelayEntity> callback) {
        BlastKool.Companion.loader().db().queryDelay(entity -> {
            callback.onSuccess(entity);
            callback.onFinish();
        });
    }

    default void setDelay(CapDelayEntity entity, OnBaseResultCallback<CapDelayEntity> callback) {
        Timber.i("setDelay");
        BlastKool.Companion.loader().db().updateDelay(entity, () -> {
            callback.onSuccess(entity);
            callback.onFinish();
        });
    }

    default void setDelay(String planId, boolean isKeepSort, long startDelay, long rowDelay, long holeDelay, OnBaseResultCallback<ReadResult> callback) {
        Timber.i("setDelay#plant:" + planId + ",isKeepSort:" + isKeepSort + ",startDelay:" + startDelay + ",rowDelay:" + rowDelay + ",holeDelay:" + holeDelay);
        BlastKool.Companion.loader().sort().batchUpdateCaps(planId, startDelay, rowDelay, holeDelay, isKeepSort, readResult -> {
            callback.onSuccess(readResult);
            callback.onFinish();
        });
    }
}
